package com.gloabalroam.testleak;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import com.gloabalroam.testleak.adapter.MyFragmentPagerAdapter;
import com.gloabalroam.testleak.fragment.FirstFragment;
import com.gloabalroam.testleak.fragment.SecondFragment;
import com.gloabalroam.testleak.fragment.ThreeFragment;
import com.gloabalroam.testleak.widget.ViewPagerIndicator;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private ViewPager viewPager;
    private ViewPagerIndicator indicator;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        indicator = (ViewPagerIndicator) findViewById(R.id.indicator);

        viewPager = (ViewPager) findViewById(R.id.view_pager);
        List<Fragment> fragments = new ArrayList<>();
        fragments.add(new FirstFragment());
        fragments.add(new SecondFragment());
        fragments.add(new ThreeFragment());

        MyFragmentPagerAdapter fragmentPagerAdapter = new MyFragmentPagerAdapter(getSupportFragmentManager(),fragments);
        viewPager.setAdapter(fragmentPagerAdapter);
        viewPager.addOnPageChangeListener(indicator);
    }

    public void changePage(View view)
    {
        switch(view.getId())
        {
            case R.id.circle:
                viewPager.setCurrentItem(0,true);
                break;
            case R.id.all:

                viewPager.setCurrentItem(1,true);
                break;
            case R.id.contacts:
                viewPager.setCurrentItem(2,true);
                break;
        }
    }


}
